<!DOCTYPE HTML>
<html  xmlns:th="http://www.thymeleaf.org">
<head th:include="_meta :: header">
<title>添加权限节点</title>
</head>


<body>
<div class="layui-fluid">
	<div class="layui-row">

	<form id="form-admin-add" class="layui-form" action="#" th:action="@{/resource/add-permission}" th:object="${resource}" method="post"  >
    <input type="hidden" name="save" value="true"/>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="x-red">*</span>名称：</label>
		<div class="layui-input-inline">
			<input type="text" class="layui-input" value="" placeholder="" th:field="*{name}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">父级名称：</label>
		<div class="layui-input-inline">
			<select class="select"  size="1" th:field="*{parentId}">
				<option th:each="resource : ${resourceList}"
						th:value="${resource.id}"
						th:text="${resource.name}">顶级栏目</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">资源类型：</label>
		<div class="layui-input-inline">
			<select class="select" size="1" th:field="*{type}">
				<option th:each="type : ${types}"
						th:value="${type.toString() eq 'menu'} ? '0' : '1'"
						th:text="${type.toString() eq 'menu'} ? '菜单' : '按钮'"></option>
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">路由：</label>
		<div class="layui-input-inline">
			<input type="text" class="layui-input" autocomplete="off"  th:field="*{url}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">权限：</label>
		<div class="layui-input-inline">
			<input type="text" class="layui-input" autocomplete="off"  th:field="*{permission}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">排序：</label>
		<div class="layui-input-inline">
			<input type="text" class="layui-input" autocomplete="off"  th:field="*{orderNum}"/>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"></label>
		<div class="layui-input-inline">
			<button  class="layui-btn" id="subbtn" type="submit">
				提交
			</button>
		</div>
	</div>
	</form>
	</div>
</div>


<!--_footer 作为公共模版分离出去--> 
<div th:replace="_footer :: footerjs">
</div>
 <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/jquery.validate.js}" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/validate-methods.js}" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" th:src="@{/lib/jquery.validation/1.14.0/messages_zh.js}"  src="lib/jquery.validation/1.14.0/messages_zh.js"></script> 
<script type="text/javascript">
$(function(){
	layui.use(['form', 'layer'],function() {
		$ = layui.jquery;
		var form = layui.form,
				layer = layui.layer;
	});


	$("#form-admin-add").validate({
		rules:{
			name: "required", 
			orderNum:{
				required:true,
				digits:true
			},
		
		},
		 messages: {  
			   name: "资源名称不能为空",  
			   orderNum: {  
			    required: "排序字段不能为空",  
			    digits: "请输入整数"  
			   }, 
		 },
		onkeyup:false,
		//focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "/resource/add-permission" ,
				success: function(data){
					layer.msg('添加成功!',{icon:1,time:1000},function(){
						var index = parent.layer.getFrameIndex(window.name);
						parent.location.reload();
						parent.layer.close(index); 
					});
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:1,time:1000});
				}
			});
		
		}
	});
});


</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>